{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "539ef7ac-706a-41dc-8a37-376a00d4b057",
   "metadata": {},
   "source": [
    "https://leetcode.com/problems/swap-nodes-in-pairs\n",
    "\n",
    "\n",
    "Runtime: 0 ms, faster than 100.00% of Go online submissions for Swap Nodes in Pairs.\n",
    "Memory Usage: 2.2 MB, less than 7.74% of Go online submissions for Swap Nodes in Pairs.\n",
    "\n",
    "\n",
    "```go\n",
    "func swapPairs(head *ListNode) *ListNode {\n",
    "\t//6:54\n",
    "\tvar list1 = make([]*ListNode, 0)\n",
    "\tvar node = head\n",
    "\tfor node != nil {\n",
    "\t\tlist1 = append(list1, node)\n",
    "\t\tnode = node.Next\n",
    "\t}\n",
    "\tif len(list1) == 0 {\n",
    "\t\treturn nil\n",
    "\t}\n",
    "\tvar list2 = make([]*ListNode, 0)\n",
    "\tfor index, node := range list1 {\n",
    "\t\tif index%2 != 0 {\n",
    "            if len(list2) == 0 {\n",
    "\t\t\t\tlist2 = append(list2, node)\n",
    "\t\t\t} else {\n",
    "\t\t\t\tvar old_last_value = list2[len(list2)-1]\n",
    "\t\t\t\tlist2 = list2[:len(list2)-1]\n",
    "\t\t\t\tlist2 = append(list2, node)\n",
    "\t\t\t\tlist2 = append(list2, old_last_value)\n",
    "\t\t\t}\n",
    "        } else {\n",
    "            list2 = append(list2, node)\n",
    "        }\n",
    "\t}\n",
    "\tfor index, node := range list2 {\n",
    "\t\tif index == len(list2)-1 {\n",
    "\t\t\tnode.Next = nil\n",
    "\t\t} else {\n",
    "\t\t\tnode.Next = list2[index+1]\n",
    "\t\t}\n",
    "\t}\n",
    "\treturn list2[0]\n",
    "\t//7:03\n",
    "    //debug until 7:07\n",
    "}\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f0a93e8f-cfe5-4124-9a98-69669e0f8a1f",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Go",
   "language": "go",
   "name": "gophernotes"
  },
  "language_info": {
   "codemirror_mode": "",
   "file_extension": ".go",
   "mimetype": "",
   "name": "go",
   "nbconvert_exporter": "",
   "pygments_lexer": "",
   "version": "go1.14.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
